package com.zhou.yygh.msm.service.impl;

import com.zhou.yygh.msm.service.MsmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class MsmServiceImpl  implements MsmService {


    @Autowired
    private JavaMailSenderImpl javaMailSender;
    @Value("${spring.mail.username}")
    private String from;
    @Override

    public boolean send(String phone, String code) {
        if(StringUtils.isEmpty(phone)){
            return false;
        }
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setSubject("挂号平台验证码");
        mailMessage.setText("[挂号平台]验证码"+code+",2分中内有效，请勿泄露");
        mailMessage.setFrom(from);
        mailMessage.setTo(phone);
        javaMailSender.send(mailMessage);
        return true;
    }
}


